package com.ihg.hiex.admin.web.controller.session.during;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.demo2do.core.web.interceptor.MenuSetting;
import com.ihg.hiex.admin.entity.security.Login;
import com.ihg.hiex.admin.service.session.SessionDuringService;
import com.ihg.hiex.admin.service.session.SessionTaskService;
import com.ihg.hiex.admin.web.resolver.Secure;
import com.ihg.hiex.entity.session.during.SessionCalibration;
import com.ihg.hiex.entity.session.during.SessionCalibrationAnchorScore;
import com.ihg.hiex.entity.session.during.SessionCalibrationComment;
import com.ihg.hiex.entity.session.during.SessionCalibrationCompetency;
import com.ihg.hiex.entity.session.during.SessionCalibrationRecommendation;
import com.ihg.hiex.entity.session.participator.Type;
import com.ihg.hiex.entity.session.task.SessionTask;

/**
 * 
 * @author Sanz
 *
 */
@Controller
@RequestMapping("/sessions/{sessionId}/peer-calibrations")
@MenuSetting("menu-sessions")
public class ReportReviewController {
    
    @Autowired
    private SessionDuringService sessionDuringService;
    
    @Autowired
    private SessionTaskService sessionTaskService;
    
    
    /**
     * 
     * @param login
     * @param sessionId
     * @param calibrationId
     * @return
     */
    @MenuSetting(value = "submenu-session-during-day-three")
    @RequestMapping(path = "/{calibrationId}/development-day-report-view", method = RequestMethod.GET)
    public ModelAndView reportWriting(@Secure Login login,
                                      @PathVariable("sessionId") Long sessionId,
                                      @PathVariable("calibrationId") Long calibrationId) {
        
        ModelAndView modelAndView = new ModelAndView("session/during/peer-calibration/peer-calibration-development-report-view");
        
        SessionCalibration sessionCalibration = sessionDuringService.loadSessionCalibration(calibrationId);
        modelAndView.addObject("sessionCalibration", sessionCalibration);
        
        List<SessionCalibrationCompetency> competencies = sessionDuringService.listSessionCalibrationCompetency(sessionCalibration);
        modelAndView.addObject("competencies", competencies);
        
        SessionCalibrationComment comment = sessionDuringService.loadSessionCalibrationComment(sessionCalibration);
        modelAndView.addObject("comment", comment);
        
        SessionCalibrationRecommendation recommendation = sessionDuringService.loadSessionCalibrationRecommendation(sessionCalibration);
        modelAndView.addObject("recommendation", recommendation);
        
        SessionTask sessionTask = sessionTaskService.load(sessionCalibration.getSession(), sessionCalibration.getLeadAssessor(), sessionCalibration.getDelegate(), Type.ASSESSOR, "Peer Calibration Report");
        modelAndView.addObject("sessionTask", sessionTask);
        
        // load sessionCalibrationCompetency
        List<SessionCalibrationCompetency> sessionCalibrationCompetencies = sessionDuringService.listSessionCalibrationCompetency(sessionCalibration);
        modelAndView.addObject("sessionCalibrationCompetencies", sessionCalibrationCompetencies);
        
        // list strength and development needs anchorScore
        Map<String, Map<String, List<SessionCalibrationAnchorScore>>> anchorScores = sessionDuringService.listSessionCalibrationAnchorScore(sessionCalibrationCompetencies);
        modelAndView.addObject("anchorScores", anchorScores);
        
        
        modelAndView.addObject("sessionId", sessionId);
        
        modelAndView.addObject("justView", true);
        
        return modelAndView;
        
    }
    
}
